home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Plotter Lib / Demo Plotter Lib.rsrc / MODL_18195_Plotter, MultiSim < prev    next >
Encoding:
Text File  |  1994-07-26  |  6.5 KB  |  247 lines

  1. real    p0[], p1[], p2[], p3[];
  2. real     timeArray[];            ** for discrete event Exec testing
  3. integer    in0;
  4.  
  5. **     This plotter overlays inputs from different simulations
  6. **    for easy comparison.
  7. **    Copyright © 1989-1994 by Imagine That, Inc.
  8. **    All Rights Reserved.
  9. ** Extend Plotter Library, Plotter Multisim block;Alfy Riddle 8/15/89
  10. **        modified     1/1/92 JSL Modified for V2.0
  11. **                    12/8/92 JSL added numSims > 1 to initSim code
  12. **                    4/1/94    DJK modified trace and report
  13. **                    6/2/94     DJK added openModel message handler
  14.  
  15. on checkData
  16. {
  17.     sysGlobal1 = 0.0;
  18.     sysGlobal2 = 0.0;
  19.     
  20.     ** Find out if inputs are connected to determine
  21.     ** which are being used as input or output
  22.     ** and save their states for plotting decisions
  23.     ** in simulate message
  24.     in0 = Con0In;    ** save values for later decisions
  25. }
  26.  
  27.  
  28. on initsim
  29. {
  30.     **    First check to make sure Discrete Event Exec is not being used
  31.     if( getPassedArray(sysGlobal0, timeArray) )
  32.         {
  33.         userError("The Plotter, MultiSim does not work with the Discrete Event Exec in block number "+(MyBlockNumber()));
  34.         abort;
  35.         }
  36.  
  37.     ** if no inputs are connected, don't do anything
  38.     ** so that the user can use the saved data for input
  39.     if (not in0)
  40.         return;
  41.  
  42.     ** check each input connector.  If it is connected
  43.     ** the user is using that signal to plot simulation
  44.     ** results, so resize the array using makeArray.
  45.     
  46.     ** If it isn't used, compress the signal array
  47.     
  48.     if( nextLine == 1 || (currentSim == 0 && numSims > 1) )
  49.         {
  50.         makeArray(p0, numsteps);    ** yes, input.  Resize array
  51.         installArray(0, 0, "", p0, startTime, endTime, 
  52.                     0, 0, blackPattern, cyanColor);
  53.         }
  54.     if( nextLine == 2 || (currentSim == 0 && numSims > 1) )
  55.         {
  56.         makeArray(p1, numsteps);    ** yes, input.  Resize array
  57.         installArray(0, 1, "", p1, startTime, endTime, 
  58.                     0, 0, dkgrayPattern, redColor);
  59.         }
  60.     if( nextLine == 3 || (currentSim == 0 && numSims > 1) )
  61.         {
  62.         makeArray(p2, numsteps);    ** yes, input.  Resize array
  63.         installArray(0, 2, "", p2, startTime, endTime, 
  64.                     0, 0, grayPattern, greenColor);
  65.         }
  66.     if( nextLine == 4 || (currentSim == 0 && numSims > 1) )
  67.         {
  68.         makeArray(p3, numsteps);    ** yes, input.  Resize array
  69.         installArray(0, 3, "", p3, startTime, endTime, 
  70.                     0, 0, ltgrayPattern, blackColor);
  71.         }
  72.                 
  73.     retimeAxis(0);
  74.     
  75.     if( showDuring )
  76.         showPlot(0, "Plotter, Multisim");
  77. }
  78.  
  79.  
  80. on simulate
  81. {
  82.     ** check each saved input connector state
  83.     
  84.     ** if it is TRUE, the input connector was
  85.     ** connected, so plot the new point and also
  86.     ** pass the value to the output in case it is
  87.     ** also connected.
  88.     
  89.     ** if it is FALSE, the input connector wasn't
  90.     ** connected, so get the output value from
  91.     ** the previously stored signal in the plot
  92.     ** and put it in the output connector
  93.  
  94.     if( nextLine == 1 )
  95.         {
  96.         plotNewPoint(0,0,currentStep,con0in);
  97.         }
  98.     else if( nextLine == 2 )
  99.         {
  100.         plotNewPoint(0,1,currentStep,con0in);
  101.         }
  102.     else if( nextLine == 3 )
  103.         {
  104.         plotNewPoint(0,2,currentStep,con0in);
  105.         }
  106.     else if( nextLine == 4 )
  107.         {
  108.         plotNewPoint(0,3,currentStep,con0in);
  109.         }
  110.  
  111.     ** sysGlobal2 is the file reference number for the DEBUG TRACE
  112.     if( sysGlobal2 != 0.0 ) ** 0 is error, check for open file for TRACE
  113.         {
  114. // template for trace:       |BLOCK NAME *****************|block number |BLOCK NUMBER*******|.| Current Time:|CURRENTTIME  |.|
  115.         fileWrite(sysGlobal2,"Plotter,Multisim             block number "+(myBlockNumber())+".  Current Time:"+currentTime+".","",True);
  116.         if(getBlockLabel(myBlockNumber()) != "")
  117.             fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  118.         fileWrite(sysGlobal2,"     Input = "+con0In,"",True);
  119.         fileWrite(sysGlobal2," ","",True);
  120.         }
  121. }
  122.  
  123.  
  124. on endsim
  125. {    
  126.     integer    i, loop;
  127.     integer    size0, size1, size2, size3;
  128.     string    str;
  129.  
  130.     if( autoIncr )
  131.         nextLine = (nextLine mod 4) + 1;
  132.  
  133.     if( Con0In and showEnd and (numsims == (currentsim + 1)) )    // show plot at end if selected
  134.         showPlot(0, "Plotter, Multisim");
  135.     
  136.     if( in0 )
  137.         pushPlotPic(0);
  138.  
  139.     ** sysGlobal1 is the file reference number for the TEXT REPORT
  140.     if( sysGlobal1 != 0.0 )     ** 0 is error, check for open file for REPORT
  141.         {
  142. // template for report:      |BLOCK NAME *****************|block number |BLOCK NUMBER*******
  143.         fileWrite(sysGlobal1,"Plotter, Multisim            block number "+(myBlockNumber()),"",True);
  144.         if(getBlockLabel(myBlockNumber()) != "")
  145.             fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
  146.         if( comments != "" )
  147.             fileWrite(sysGlobal1,"     "+comments,"",True);
  148.         fileWrite(sysGlobal1,"  Input Parameters:","",True);
  149.         if( showDuring )
  150.             fileWrite(sysGlobal1,"     Plot is shown during simulation","",True);
  151.         else
  152.             fileWrite(sysGlobal1,"     Plot is hidden during simulation","",True);
  153.  
  154.         if( !noValue(nextLine) )
  155.             fileWrite(sysGlobal1,"     Next plot line = "+nextLine,"",True);
  156.     
  157.         size0 = GetDimension(p0);
  158.         size1 = GetDimension(p1);
  159.         size2 = GetDimension(p2);
  160.         size3 = GetDimension(p3);
  161.  
  162.         i = 0;
  163.         loop = TRUE;
  164.         while(loop)
  165.             {
  166.             str = "";
  167.             if (i < size0)
  168.                 str = p0[i];
  169.             str += "    ";
  170.             if (i < size1)
  171.                 str += p1[i];
  172.             str += "    ";
  173.             if (i < size2)
  174.                 str += p2[i];
  175.             str += "    ";
  176.             if (i < size3)
  177.                 str += p3[i];
  178.  
  179.             fileWrite(sysGlobal1, str, "", true);
  180.             i++;
  181.             if (i >= numSteps-1)
  182.                 {
  183.                 loop = FALSE;
  184.                 break;
  185.                 }
  186.             if (i >= size0 && i >= size1 && i >= size2 && i >= size3)
  187.                 loop = FALSE;
  188.             }
  189.         fileWrite(sysGlobal1," ","",True);
  190.         }
  191. }
  192.  
  193.  
  194. on dialogOpen
  195. {
  196.     showplot(0, "Plotter, MultiSim");
  197.     abort;    ** stop the dialog from opening!
  198. }
  199.  
  200.  
  201. on showP
  202. {
  203.     showplot(0, "Plotter, MultiSim");
  204. }
  205.  
  206. on createBlock
  207. {
  208.     **    First check to make sure Discrete Event Exec is not being used
  209.     if( getPassedArray(sysGlobal0, timeArray) )
  210.         {
  211.         userError("The Plotter, MultiSim does not work with the Discrete Event Exec in block number "+MyBlockNumber());
  212.         abort;
  213.         }
  214.  
  215.     ** install a dummy axis
  216.     installAxis(0, "Plotter, MultiSim", "Time", FALSE, 0.0, 1.0,
  217.             "Value", 0, -1.0, 1.0, "Y2", 0, 0.0, 0.0, 
  218.             blackpattern, blackcolor, 100);
  219.     
  220.     ** now, install 4 dummy array signals
  221.     ** to store plotting values from a simulation
  222.     ** or from Pasting (Importing) tabular data
  223.     
  224.     makeArray(p0, 0);
  225.     installArray(0, 0, "Blue", p0, 0.0, 1.0, 
  226.                     0, 0, blackPattern, cyanColor);
  227.     makeArray(p1, 0);
  228.     installArray(0, 1, "Red", p1, 0.0, 1.0,
  229.                     0, 0, dkgrayPattern, redColor);
  230.     makeArray(p2, 0);
  231.     installArray(0, 2, "Green", p2,0.0, 1.0, 
  232.                     0, 0, grayPattern, greenColor);
  233.     makeArray(p3, 0);
  234.     installArray(0, 3, "Gray", p3, 0.0, 1.0,
  235.                     0, 0, ltgrayPattern, blackColor);
  236.                     
  237.     showDuring = 1;        ** default show plot during simulation
  238.     nextLine = 1;
  239.     autoIncr = 1;        ** auto step plot line used
  240. }
  241.  
  242.  
  243. on openModel
  244. {
  245.     if(!showDuring && !showEnd && !noPlot)
  246.         noPlot = 1;
  247. }